package com.kfm.system.service.impl;

import com.kfm.common.domain.entity.Menu;
import com.kfm.common.domain.model.LoginUser;
import com.kfm.common.util.SecurityUtils;
import com.kfm.system.mapper.MenuMapper;
import com.kfm.system.service.MenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService{

    @Resource
    private MenuMapper menuMapper;

    @Override
    public int deleteByPrimaryKey(Integer menuId) {
        return menuMapper.deleteByPrimaryKey(menuId);
    }

    @Override
    public int insert(Menu record) {
        return menuMapper.insert(record);
    }

    @Override
    public int insertSelective(Menu record) {
        return menuMapper.insertSelective(record);
    }

    @Override
    public Menu selectByPrimaryKey(Integer menuId) {
        return menuMapper.selectByPrimaryKey(menuId);
    }

    @Override
    public int updateByPrimaryKeySelective(Menu record) {
        return menuMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Menu record) {
        return menuMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Menu> selectAll() {
        return menuMapper.selectAll();
    }

    @Override
    public List<Menu> selectByCondition(Menu menu) {
        return menuMapper.selectByCondition(menu);
    }

    @Override
    public List<Menu> selectMenus() {
        LoginUser user = SecurityUtils.getUser();
        if (user != null) {
            if (user.isAdmin()) {
                return menuMapper.selectAll();
            }
            return menuMapper.selectByUserId(user.getUser().getId());
        }
        return null;

    }

}
